#!/usr/bin/python
#coding:utf-8
'''
http接口测试工具类
'''
import base64
from urllib import request
import json

def fileToBase64(file):
    '''
    图片转base64
    '''
    with open(file, 'rb') as fin:
        image_data = fin.read()
        image_base64 = str(base64.b64encode(image_data))
        return image_base64

headers ={
    "content-type":"application/json"
}

def requestTest():
    img="E:/python-workspace/2020/cv2/158096145222.jpg"
    baseImg=fileToBase64(img)
    context={"code":"2020_09_03","originalImage":baseImg,"image":baseImg,"imageType":1}
    req = request.Request(url = "http://localhost:8081/ocr/led",
                headers = headers,
                data = json.dumps(context).encode("utf-8"))
                
    reps = request.urlopen(req).read().decode("utf-8")
    print(reps)